package com.jzt.qf.service.impl;

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.UploadBase;
import com.jzt.qf.beans.jztBean.InStockPlan_Upload;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.BuyBillDao;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.https.JztApi;
import com.jzt.qf.service.BuyBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 　* @description:采购单service实现类
 * 　* @author zxy
 * 　* @date 2020-07-23 14:58
 */
@Service
@Slf4j
public class BuyBillServiceImpl implements BuyBillService {
    @Resource
    private BuyBillDao buyBillDao;
    @Resource
    private UploadbillJztDao uploadbillJztDao;
    @Resource
    private JztApi jztApi;
    @Override
    public HttpResult uoloadBuyBill(String BillCode) {
        log.info("上传采购订单BuyBillServiceImpl访问成功");
        //获取采购订单
        List<InStockPlan_Upload> inStockPlan_uploads =
                buyBillDao.getBuyBill_Upload(BillCode);
        log.info("上传采购订单数据" + JSON.toJSONString(inStockPlan_uploads));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("rk", "saveData", inStockPlan_uploads));
        log.info("上传采购订单返回数据" + JSON.toJSONString(httpResult));
        //TODO 修改中间库数据
        if (httpResult.isFlag()) {
            for (InStockPlan_Upload inStockPlan_upload : inStockPlan_uploads) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(inStockPlan_upload.getBUSINESSBILL_NO());
                zxyUploadbillJzt.setOrd(Integer.parseInt(inStockPlan_upload.getBILL_DTL_ID_OLD()));
                zxyUploadbillJzt.setBilltype(34);
                uploadbillJztDao.updateFlags(zxyUploadbillJzt);
            }
        }
        return httpResult;
    }

    @Override
    public HttpResult getBuyChecked(UploadBase uploadBase) {
        return null;
    }

//    @Override
//    public HttpResult<GET_InStock> getJZTBuyBill(String billCode) {
//        JztRKJson jztRKJson = new JztRKJson(billCode,"1");
//        UploadBase<JztRKJson> jztRKJsonUploadBase= new UploadBase("rksc","select",jztRKJson);
//        log.info("获取九州通入库单查询条件"+JSON.toJSONString(jztRKJsonUploadBase));
//        HttpResult<GET_InStock> httpResult = JztApi.HttpRequest(jztRKJsonUploadBase);
//        log.info("获取九州通入库单返回的数据"+JSON.toJSONString(httpResult));
//        return httpResult;
//    }
}
